app.controller('GetOneDeviceCtrl',function($scope,$http,$localStorage,$location,$window,$state){
  $scope.namedata = $localStorage.cur_user.uname;
  // $scope.oo = {};
  $http.post(
            $scope.app.backendurl+"tbl-equipment/view-one",
            {    
                'equipment_id':$state.params.devid,               
                'token':$localStorage.token 
            }
          ).success(function (data) {
            //console.log(data);
            if(data.code==0&&data.msg=="获取设备详细数据成功"){
              $scope.aaData = data.data;           
            }
            if(data.code==1){
              alert(data.msg)
            }
            if(data.code==20001&&data.msg=='请先登录'){
              $location.path('access.signin');
            }      
        }).error(function(data){
          console.log(data);
        })

 
    $scope.savebasicinfo = function(){       
      
        $http.post(
            $scope.app.backendurl+"tbl-equipment/update-basic-info",
            {    
                'equipment_id':$state.params.devid,  
                'equipment_name':$scope.aaData.equipment_name,
                'brand':$scope.aaData.brand,
                'version':$scope.aaData.version,            
                'token':$localStorage.token                  

            }
          ).success(function (data) {
            //console.log(data);
            if(data.code==0&&data.msg=="设备基本信息修改成功"){
              alert(data.msg);
              $state.go('app.sys.editdev',{devid:$state.params.devid,epage:$state.params.ebpage,pid:$scope.aaData.product_name})         
            }
            if(data.code==1){
              alert(data.msg)
            }
            if(data.code==20001&&data.msg=='请先登录'){
              $location.path('access.signin');
            }      
        }).error(function(data){
          console.log(data);
        })
    }

    $scope.saveadditionalinfo = function(){      
       
        $http.post(
            $scope.app.backendurl+"tbl-equipment/update-other-info",
            {    
                'equipment_id':$state.params.devid,  
                'installer':$scope.aaData.installer,
                'install_date':moment($scope.aaData.install_date).format('YYYY-MM-DD'),
                'equipment_date':moment($scope.aaData.equipment_date).format('YYYY-MM-DD'),
                'version':$scope.aaData.version,            
                'token':$localStorage.token                  

            }
          ).success(function (data) {
            //console.log(data);
            if(data.code==0&&data.msg=="设备基本信息修改成功"){
              alert("设备附加信息修改成功");
              $state.go('app.sys.editdev',{devid:$state.params.devid,epage:$state.params.eadpage,pid:$scope.aaData.product_name})         
            }
            if(data.code==1){
              alert(data.msg)
            }
            if(data.code==20001&&data.msg=='请先登录'){
              $location.path('access.signin');
            }      
        }).error(function(data){
          console.log(data);
        })
    }

})

app.controller('DatepickerCtrl', ['$scope', function ($scope) {
        // $scope.aaData = {};
        // $scope.aaData.chuchangriqi = new Date();
        // $scope.aaData.anzhuangriqi = new Date();
        

        $scope.clear = function (){
            $scope.aaData.chuchangriqi = null;
            $scope.aaData.anzhuangriqi = null;
        };

        // Disable weekend selection
        $scope.disabled = function (date, mode) {
            return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 ) );
        };

        $scope.toggleMin = function () {
            $scope.minDate = $scope.minDate ? null : new Date();
        };
        $scope.toggleMin();

        $scope.open = function ($event) {
            $event.preventDefault();
            $event.stopPropagation();

            $scope.opened = true;
        };

        $scope.dateOptions = {
            formatYear: 'yy',
            startingDay: 1,
            class: 'datepicker'
        };

        $scope.initDate = new Date('0000-00-00');
        $scope.formats = ['yyyy-MM-dd', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
        $scope.format = $scope.formats[0];
    }])